package com.example.demo.service;

import com.example.demo.model.User;
import com.example.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterService {
    @Autowired
    private UserRepository userRepository;

    public void save(User user) throws Exception{
        if(userRepository.findByUsername(user.getUsername()).isEmpty()==false){
            throw new Exception("Username already exists when creating");
        }
        userRepository.save(user);
    }
}
